package com.huawei.secure.android.common.ssl;

import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import o.avb;

public class g {
    private static final String TAG = "X509CertificateUtil";
    private static final String ac = "052root";
    private static final String ad = "hmsincas.bks";
    private static final String ae = "huawei cbg application integration ca";
    private static final String b = "bks";
    private static final String k = "hmsrootcas.bks";
    private static final String l = "";
    private static int ˊ = 157;
    private static int ˋ = 1;
    private static final byte[] ˎ = new byte[]{(byte) 93, (byte) -48, (byte) -52, (byte) 29, (byte) 6, (byte) -24, (byte) 18, (byte) 48, (byte) -72, (byte) 11, (byte) -1, (byte) -21, (byte) 0, (byte) 6, (byte) -14, (byte) -8, (byte) 72, (byte) -32, (byte) -29, (byte) -23, (byte) 35, (byte) -36, (byte) 2, (byte) -6, (byte) 10, (byte) -1, (byte) -18, (byte) 40, (byte) -40, (byte) -8, (byte) -4, (byte) 16, (byte) -16, (byte) 8, (byte) -5};
    private static int ॱ = 0;
    private Context p;

    private static java.lang.String ˊ(int r7, short r8, byte r9) {
        /* JADX: method processing error */
/*
Error: jadx.core.utils.exceptions.JadxOverflowException: Regions stack size limit reached
	at jadx.core.utils.ErrorsCounter.addError(ErrorsCounter.java:37)
	at jadx.core.utils.ErrorsCounter.methodError(ErrorsCounter.java:61)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:33)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:17)
	at jadx.core.ProcessClass.process(ProcessClass.java:37)
	at jadx.core.ProcessClass.processDependencies(ProcessClass.java:59)
	at jadx.core.ProcessClass.process(ProcessClass.java:42)
	at jadx.api.JadxDecompiler.processClass(JadxDecompiler.java:306)
	at jadx.api.JavaClass.decompile(JavaClass.java:62)
*/
        /*
        r3 = -1;
        r0 = r9 * 3;
        r0 = 106 - r0;
        r1 = r8 * 11;
        r2 = r1 + 11;
        r6 = ˎ;
        r1 = r7 * 21;
        r4 = 25 - r1;
        r1 = new byte[r2];
        r2 = r2 + -1;
        if (r6 != 0) goto L_0x0030;
    L_0x0015:
        r5 = r4;
        r4 = r3;
        r3 = r1;
        r1 = r2;
    L_0x0019:
        r0 = -r0;
        r0 = r0 + r1;
        r5 = r5 + 1;
        r1 = r0 + -3;
    L_0x001f:
        r4 = r4 + 1;
        r0 = (byte) r1;
        r3[r4] = r0;
        if (r4 != r2) goto L_0x002d;
    L_0x0026:
        r0 = new java.lang.String;
        r1 = 0;
        r0.<init>(r3, r1);
        return r0;
    L_0x002d:
        r0 = r6[r5];
        goto L_0x0019;
    L_0x0030:
        r5 = r4;
        r4 = r3;
        r3 = r1;
        r1 = r0;
        goto L_0x001f;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.secure.android.common.ssl.g.ˊ(int, short, byte):java.lang.String");
    }

    public g(Context context) {
        this.p = context;
    }

    public X509Certificate a(String str, String str2) {
        Exception exception;
        InputStream inputStream;
        Exception exception2;
        Throwable th;
        InputStream inputStream2 = null;
        try {
            byte b = (byte) (-ˎ[10]);
            byte b2 = (byte) ˎ[12];
            Object invoke = Class.forName(ˊ(b, (byte) b, (byte) ˎ[12])).getMethod(ˊ(b2, (byte) b2, (byte) (-ˎ[10])), new Class[]{String.class}).invoke(null, new Object[]{b});
            AssetManager assets = this.p.getAssets();
            InputStream inputStream3 = (InputStream) ((Class) avb.ˏ(5, 0, '㮃')).getMethod("ˏ", new Class[]{AssetManager.class, String.class}).invoke(null, new Object[]{str, assets});
            try {
                inputStream3.reset();
                String str3 = "";
                int i = ˋ + 81;
                ॱ = i % DnsConfig.MAX_CACHE_ENTRIES;
                if (i % 2 != 0) {
                }
                Object invoke2 = String.class.getMethod("toCharArray", null).invoke(str3, null);
                i = ˋ + 115;
                ॱ = i % DnsConfig.MAX_CACHE_ENTRIES;
                if (i % 2 != 0) {
                }
                Object[] objArr = new Object[]{invoke2, inputStream3};
                b2 = (byte) (-ˎ[10]);
                Class.forName(ˊ(b2, (byte) b2, (byte) ˎ[12])).getMethod("load", new Class[]{InputStream.class, char[].class}).invoke(invoke, objArr);
                byte b3 = (byte) (-ˎ[10]);
                X509Certificate x509Certificate = (X509Certificate) Class.forName(ˊ(b3, (byte) b3, (byte) ˎ[12])).getMethod("getCertificate", new Class[]{String.class}).invoke(invoke, new Object[]{str2});
                d.a(inputStream3);
                return x509Certificate;
            } catch (Exception e) {
                exception = e;
                inputStream = inputStream3;
                exception2 = exception;
            } catch (Exception e2) {
                exception = e2;
                inputStream = inputStream3;
                exception2 = exception;
            } catch (Exception e22) {
                exception = e22;
                inputStream = inputStream3;
                exception2 = exception;
            } catch (Exception e222) {
                exception = e222;
                inputStream = inputStream3;
                exception2 = exception;
            } catch (Throwable th2) {
                inputStream2 = inputStream3;
                th = th2;
                d.a(inputStream2);
                throw th;
            }
        } catch (KeyStoreException e3) {
            exception2 = e3;
            inputStream = null;
        } catch (CertificateException e4) {
            exception2 = e4;
            inputStream = null;
        } catch (IOException e5) {
            exception2 = e5;
            inputStream = null;
        } catch (NoSuchAlgorithmException e6) {
            exception2 = e6;
            inputStream = null;
        } catch (Throwable th3) {
            th = th3;
            d.a(inputStream2);
            throw th;
        }
        try {
            Log.e(TAG, "loadBksCA: exception : " + exception2.getMessage());
            d.a(inputStream);
            return null;
        } catch (Throwable th4) {
            th = th4;
            inputStream2 = inputStream;
            d.a(inputStream2);
            throw th;
        }
    }

    public X509Certificate d() {
        return a("hmsrootcas.bks", ac);
    }

    public X509Certificate e() {
        return a(ad, ae);
    }
}
